import {ethers} from "ethers"

// 正则表达式 匹配以0x000开头的地址
// const regex = /^0x000.*$/
// var wallet 
// var isValid = false
// while(!isValid){
//     wallet = ethers.Wallet.createRandom()
//     isValid = regex.test(wallet.address)
// }
// console.log("靓号地址：", wallet.address)
// console.log("靓号私钥：", wallet.privateKey)


/**
 * 生成100个顺序地址
 */

// 正则表达式列表
function createRegexList(total){
    const regexList = []
    for(let i =0 ; i< total ; i++){
        const paddingIndex = (i + 1).toString().padStart(1, '0')
        const regex = new RegExp(`^0x${paddingIndex}.*$`)
        regexList.push(regex)
    }
    return regexList
}

function createSerialWallet(total){
    const regexList = createRegexList(total)
    console.log(regexList)
    const privateKeys = []
    while(regexList.length > 0){
        const wallet = ethers.Wallet.createRandom()
        const index = regexList.findIndex(regex => regex.test(wallet.address))
        if(index != -1){
            console.log("找到地址:", wallet.address)
             regexList.splice(index, 1);
             privateKeys.push(wallet.privateKey)
        }
    }
    return privateKeys
}

const privateKeys = createSerialWallet(5)
for(let i=0;i<privateKeys.length;i++){
    const wallet = new ethers.Wallet(privateKeys[i])
    console.log(wallet.address)
}